package bean.lookup;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


public class TestLookUp {

	/**
	 *  https://blog.csdn.net/lyc_liyanchao/article/details/82432993?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-0&spm=1001.2101.3001.4242
	 * @param args
	 */
	public static void main(String[] args) {

		ApplicationContext context
				= new ClassPathXmlApplicationContext("bean.lookup/lookup.xml");

		// 测试lookup-method注入
		Car car1 = context.getBean("car", Car.class);
		Car car2 = context.getBean("car", Car.class);

		System.out.println("Car:singleton " + (car1 == car2));

		Taxi dog1 = car1.getTaxi();
		Taxi dog2 = car2.getTaxi();
		System.out.println("Taxi:prototype,Car:singleton,未使用lookup-method " + (dog1 == dog2));

		//注意:这里是通过createDog()方法获取
		Taxi taxi3 = car1.createTaxi();
		Taxi taxi4 = car2.createTaxi();
		System.out.println("Taxi:prototype,Car:singleton,使用了lookup-method注入 " + (taxi3 == taxi4));

	}


}
